/**
 * measure.h
 * Description:
 * Authors: Hamish Cumming, Brian Thorne 2008
 */

#ifndef MEASURE_H
#define MEASURE_H

#include "global.h"

#define SCROLL_UP 1
#define SCROLL_DOWN -1
#define BUFFER_SIZE 2
#define CROSSING_LEVEL 99
#define ADC_5V 198
#define NEGATIVE_SLOPE 0
#define POSITIVE_SLOPE 1

/**
 * A structure containing statistics for level crossings
 */
typedef struct
{
    time_t minimum; //minimum crossing interval
    time_t maximum; //maximum crossing interval
    time_t mean; //average time between crossings
    time_t previous; //the last crossing time
    uint8_t num_crossings; //total number of crossing since the last reset
} stats_t;

/**
 * Gets the stats for the current measuring period
 * @return The stats
 */
stats_t get_stats(void);

/**
 * Resets the statistics
 */
void reset_stats(void);

/**
 * The measuring task.  Measures level crossing intervals
 * @return Task exit code
 */
uint8_t measure_task(void);

/**
 * The replay task.  Formats the stats for output to the display
 * @return Task exit code
 */
uint8_t replay_task(void);

/**
 * Initialse the measure module.
 * Involves setup of the ADC, Pin interrupts...
 */
void measure_init(void);

/**
 * Disables measuring (in hardware) by disabling the pin interupts
 */
void disable_measure(void);

/**
 * Enables measuring (in hardware) by enabling the pin interrupts
 */
void enable_measure(void);

/**
 * Toggles which stats are shown on the display
 * @param direction Which way to scroll through the stats
 */
void scroll_stats(int8_t direction);
#endif
